import "package:http/http.dart" as http;
import 'dart:convert';

/// https://httpbin.org/ip  返回IP地址

// 代码摘自B站视频： https://www.bilibili.com/video/BV1rN411Z7JH
// https://pub.flutter-io.cn/packages/http
// `http: ^0.13.4` 这个版本的http请求方式与视频中讲解的不同！ 具体参考上面的http库文档

Future getIpAddress() {
  // final url = "https://httpbin.org/ip";
  var url = Uri.parse('https://httpbin.org/ip');
  return http.get(url).then((response){
    // print(response.body);
    String ip = jsonDecode(response.body)['origin'];
    return ip;
  });
}

void main() {
  getIpAddress()
      .then((ip) => print(ip))
      .catchError((error) => print(error));
}

